<template>
  <div class="ten_box">
    <m-header modile-title="练习22" go-back="true"></m-header>
    <div class="main_box">
      <!--多选情况-->
      <div style="font-size: 18px;padding: 10px 0">可点击多个选项</div>
      <div class="waiceng" v-for="(item,index) in list" :key="index">
        <div class="hang_title">1.{{item.title}}</div>
        <div class="hang">
          <label :for="type.id" class="single_box" @change="clickMe" v-for="(type, index2) in item.data" :key="index2">
            <input type="checkbox" :id="`${item.id}_${type.name}_${type.oid}`" :value="type.name">
            <span class="check_name">{{type.name}}</span>
          </label>
        </div>
      </div>

      <!--单选情况-->
      <div style="background: #fffbe6">
        <div style="font-size: 18px;padding: 10px 0">单选</div>
        <div class="zt" v-for="(r,rindex) in list2" :key="rindex">
          <div class="zt_title">{{rindex+1}}.{{r.title}}</div>
          <div class="zt_h">
            <div class="h_box" @click="choseMe(rindex,r2.rid,r2.name,rindex2)" v-for="(r2,rindex2) in r.data" :key="rindex2">
              <div class="quan" :class="[checkIndex(rindex,rindex2)?'active': '']"></div>
              <span>{{r2.name}}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="button_div" @click="getValue">提交</div>
    </div>
  </div>
</template>
<style lang="scss">
  .ten_box {
    padding-top: 60px;
    padding-bottom: 25%;
    .main_box{
      .waiceng{
        background: white;
        border-bottom: 0.25px solid #006699;
        .hang_title{
          font-size: 25px;
          padding: 10px;
        }
        .hang{
          width: 100%;
          display: flex;
          align-items: center;
          padding: 20px 10px;
          .single_box{
            width: 25%;
            display: inline-flex;
            align-items: center;
            input{
              width: 30px;
              height: 30px;
            }
            .check_name{
              font-size: 24px;
              margin-left: 10px;
            }
          }
        }
      }
      .zt{
        border-bottom: 10px solid #006699;
        .zt_title{
          width: 100%;
          font-size: 24px;
        }
        .zt_h{
          display: flex;
          width: 100%;
          padding: 20px 10px;
          .h_box{
            display: inline-flex;
            align-items: center;
            width: 25%;
            .quan{
              width: 40px;
              height: 40px;
              border: 4px solid #d86161;
              border-radius: 50%;
            }
            .active{
              position: relative;
              display: inline-block;
              width: 40px;
              height: 40px;
              background: #d86161;
              border-radius: 25px;
            }
            .active::after{
              content: "";
              position: absolute;
              left: 7px;
              top: 8px;
              width: 60%;
              height: 35%;
              border: 5px solid #fffbe6;
              border-radius: 1px;
              border-top: none;
              border-right: none;
              background: transparent;
              transform: rotate(-45deg);
            }
            span{
              font-size: 25px;
              margin-left: 10px;
            }
          }
        }
      }
      .button_div{
        position: fixed;
        width: 100%;
        height: 60px;
        background: #d86161;
        color: white;
        font-size: 25px;
        bottom: 0;
        text-align: center;
        line-height: 60px;
      }
      .button_div:after{
        content: '';
        display: block;
        width: 100%;
        height: 100%;
        pointer-events: none;
        background-image: radial-gradient(circle,#fff 10%, transparent 10.01%);
        background-repeat: no-repeat;
        background-position: 50%;
        transform: scale(10,10);
        opacity: 0;
        transition: transform .3s, opacity .5s;
      }
      .button_div:active:after{
        transform: scale(0,0);
        opacity: .3;
        transition: 0s;
      }
    }
  }
</style>
<script>
  import mHeader from '../../../../components/header'

  export default {
    data() {
      return {
        list:[
          {
            title: '周一安排',
            id: 1,
            data:[
              {
                name: '上班',
                oid: 101
              },
              {
                name: '画画',
                oid: 102
              },
              {
                name: '看电视',
                oid: 103
              },
              {
                name: '看电影',
                oid: 104
              }
            ]
          },
          {
            title: '对XX物业服务的态度是？',
            id: 2,
            data:[
              {
                name: '满意',
                oid: 201
              },
              {
                name: '不满意',
                oid: 202
              },
              {
                name: '一般',
                oid: 203
              },
              {
                name: '不与表达',
                oid: 204
              }
            ]
          },
          {
            title: '对回南天的意见。',
            id: 3,
            data:[
              {
                name: '同意',
                oid: 301
              },
              {
                name: '反对',
                oid: 302
              },
              {
                name: '弃权',
                oid: 303
              },
              {
                name: '随多数',
                oid: 304
              }
            ]
          }
        ],
        sData: [],


        list2:[
          {
            title: '下雨天？',
            num: 1,
            data:[
              {
                name: '同意',
                rid: 101
              },
              {
                name: '反对',
                rid: 102
              },
              {
                name: '弃权',
                rid: 103
              },
              {
                name: '随多数',
                rid: 104
              }
            ]
          },
          {
            title: '对晴天的看法？',
            num: 2,
            data:[
              {
                name: '反对',
                rid: 201
              },
              {
                name: '同意',
                rid: 202
              },
              {
                name: '随多数',
                rid: 203
              },
              {
                name: '弃权',
                rid: 204
              }
            ]
          }
        ],
        selectIndex: '',
        selectArr: []
      }
    },
    methods: {
      // 多选情况获取值
      clickMe(e){
        // console.log(e.target.id)
        const value = e.target.id
        var itemindex = this.sData.findIndex((item) => item===value) // 判断数组里有没有该选中值的索引
        //findindex中不符合条件就返回-1 ：注意（因为选中后再取消值也都在）
        // 符合数组里依旧存在的元素就删除，反之就添进去
        if (itemindex!==-1) {
          this.sData.splice(itemindex,1)
        } else {
          this.sData.push(value)
        }
        console.log(this.sData)
      },

      // 纯单选情况获取值
      // 选中的样式
      checkIndex(index,index2){
        const emptyArr = this.selectArr[index] || []
        const checkArr = emptyArr.slice(-1)[0]
        return checkArr === index2
      },
      choseMe(index,id,name,index2){
        this.$set(this.selectArr,index,[
          id,
          name,
          index2
        ])
      },
      getValue() {
        console.log(this.selectArr.filter((item)=>item.slice(0,-1)))
      }
    },
    components: {
      mHeader
    }
  }
</script>
